//
//  ChooseCategoryController.m
//  quickBatchManager
//
//  Created by 王定波 on 15/9/23.
//  Copyright © 2015年 jack. All rights reserved.
//

#import "ChooseProductController.h"

@interface ChooseProductController ()
{
    NSArray *categoryList;
}

@end

@implementation ChooseProductController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)setDataList:(NSArray*)list
{
    categoryList=list;
    [_tableView reloadData];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 40;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return categoryList.count;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if([_delegate respondsToSelector:@selector(didSelectData:andData:)])
    {
        ProductModel *data=[categoryList objectAtIndex:indexPath.row];
        [_delegate didSelectData:ChooseTypeProduct andData:data];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSString *reuseIdetify = @"ProductViewCell";
    ProductModel *data=[categoryList objectAtIndex:indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdetify];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdetify];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.backgroundColor=[UIColor clearColor];
    cell.textLabel.text=[NSString stringWithFormat:@"%@,￥%0.2f",data.modelNo,data.buyPrice];
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])  {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    
    
    return cell;
    
    
}


@end
